package com.sgb.kjwl.viewmodel.packers;

import android.app.Application;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.packers.MyDepartmentEntity;
import com.sgb.kjwl.model.entity.packers.OnLineEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;

import org.jetbrains.annotations.NotNull;

/**
 * @author: 王彬臣
 * @date: 2021/9/7
 * @Description: 在线联系人ViewModel
 */
public class OnLineLinkModel extends BaseViewModel {
    public MutableLiveData<OnLineEntity> ldMyDepartment=new MutableLiveData<>();

    public OnLineLinkModel(@NonNull @NotNull Application application) {
        super(application);
    }

    public void getList(String departmentId,String imId){
        NewAPIManager.getInstance().getTeamNewInterfaceAPI().getOnline().enqueue(new ICallBack<BaseEntity<OnLineEntity>>() {
            @Override
            public void onSuccess(BaseEntity<OnLineEntity> data) {
                if(data.isSuccess()){
                    if (!TextUtils.isEmpty(departmentId) && !TextUtils.isEmpty(imId)){
                        for (int i = 0; i < data.getData().getChild().size(); i++) {
                            if (departmentId.equals(data.getData().getChild().get(i).getDepartmentId())){
                                for (int i1 = 0; i1 < data.getData().getChild().get(i).getOnlineConcat().size(); i1++) {
                                    if (imId.equals(data.getData().getChild().get(i).getOnlineConcat().get(i1).getId())){
                                        data.getData().getChild().get(i).getOnlineConcat().get(i1).setSelect(true);
                                    }
                                }
                            }
                        }
                    }
                    ldMyDepartment.postValue(data.getData());
                }
            }
        });
    }
}
